package cn.iocoder.yudao.module.nmkj.dal.mysql.newscontent;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.nmkj.dal.dataobject.newscontent.NewsContentDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.nmkj.controller.admin.newscontent.vo.*;

/**
 * 新闻内容 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface NewsContentMapper extends BaseMapperX<NewsContentDO> {

    default PageResult<NewsContentDO> selectPage(NewsContentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<NewsContentDO>()
                .eqIfPresent(NewsContentDO::getTitle, reqVO.getTitle())
                .eqIfPresent(NewsContentDO::getContent, reqVO.getContent())
                .eqIfPresent(NewsContentDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(NewsContentDO::getNewsTime, reqVO.getNewsTime())
                .betweenIfPresent(NewsContentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(NewsContentDO::getStatus)
                .orderByDesc(NewsContentDO::getId));
    }

    default NewsContentDO selectAppOne(Long id) {
        NewsContentDO reqVO = new NewsContentDO();
        reqVO.setId(id);
        reqVO.setStatus(1); //用户端请求必须启用状态
        return selectOne(new LambdaQueryWrapperX<NewsContentDO>()
                .eqIfPresent(NewsContentDO::getId, reqVO.getId())
                .eqIfPresent(NewsContentDO::getStatus, reqVO.getStatus()));
    }

}